<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Example: Aligning Grid Units</title>
    <link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
    <link rel="stylesheet" href="../assets/css/main.css">
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <script src="../../build/yui/yui-min.js"></script>
</head>
<body>

<div id="doc">
    <h1>Example: Aligning Grid Units</h1>

    

    <div class="yui3-g">
        <div id="main" class="yui3-u">
            <div class="content"><div class="intro">
    <p>YUI Grids makes it easy to align units in various ways, using basic CSS properties.</p>
</div>

<div class="example newwindow">
    <a href="cssgrids-align-example.html" target="_blank" class="button">
        View Example in New Window
    </a>
</div>

<h3>Horizontal Alignment</h3>
<p>Sometimes is it desirable for  units to be horizontally centered when taking up less than 100% of the width of the containing grid.  Rather than setting the alignment for all grids, we will add an <code>ID</code> to target the specific content being aligned.  For this example, the <code>ID</code> "demo" is used, but this should be tailored to your specific content.</p>

<pre class="code prettyprint">&lt;div class=&quot;yui3-g&quot; id=&quot;demo&quot;&gt;
    &lt;div class=&quot;yui3-u-1-3&quot;&gt;&lt;p&gt;I take up 1&#x2F;3 of my container.&lt;&#x2F;p&gt;&lt;&#x2F;div&gt;
    &lt;div class=&quot;yui3-u-1-3&quot;&gt;&lt;p&gt;I take up 1&#x2F;3 of my container.&lt;&#x2F;p&gt;&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;</pre>


<p>Using the CSS <code>text-align</code> property on the containing grid tells the units inside of a grid how to align.  We will also reset the centering so that subsequent content is left-aligned.</p>

<pre class="code prettyprint">&lt;style&gt;
#demo {
    text-align: center;
}

#demo .yui3-u-1-3 {
    text-align: left;
}
&lt;&#x2F;style&gt;</pre>


<h3>Vertical Alignment</h3>
<p>Vertical alignment tells mixed height units how they should align relative to one another, so at least 2 units are required.</p>

<pre class="code prettyprint">&lt;div class=&quot;yui3-g thumb-captions&quot;&gt;
    &lt;div class=&quot;yui3-u-1-3&quot;&gt;
        &lt;a href=&quot;#&quot;&gt;&lt;img width=&quot;80&quot; height=&quot;60&quot; src=&quot;museum.jpg&quot;&gt;
            Lorem ispum
        &lt;&#x2F;a&gt;
    &lt;&#x2F;div&gt;
    &lt;div class=&quot;yui3-u-1-3&quot;&gt;
        &lt;a href=&quot;#&quot;&gt;&lt;img height=&quot;80&quot; width=&quot;60&quot; src=&quot;museum.jpg&quot;&gt;
            Lorem ispum
        &lt;&#x2F;a&gt;
    &lt;&#x2F;div&gt;
    &lt;div class=&quot;yui3-u-1-3&quot;&gt;
        &lt;a href=&quot;#&quot;&gt;&lt;img height=&quot;80&quot; width=&quot;60&quot; src=&quot;museum.jpg&quot;&gt;
            Lorem ispum
        &lt;&#x2F;a&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;</pre>


<p>Each unit needs to be told how it should align using the CSS <code>vertical-align</code> property.  In this case, we want them all to be bottom aligned.</p>

<pre class="code prettyprint">&lt;style&gt;
.thumb-captions .yui3-u-1-3 {
    vertical-align: bottom;
}
&lt;&#x2F;style&gt;</pre>


<h3>Vertically Center a Single Unit</h3>
<p>Its possible to vertically center a single unit, although a second stub unit is required for it to align with.</p>

<pre class="code prettyprint">&lt;div class=&quot;yui3-g&quot; id=&quot;demo&quot;&gt;
    &lt;div class=&quot;yui3-u align-stub&quot;&gt;&lt;&#x2F;div&gt;
    &lt;div class=&quot;yui3-u-1-3&quot;&gt;
        &lt;p&gt;Cras porta venenatis egestas. Vestibulum pretium massa id turpis varius iaculis.&lt;&#x2F;p&gt;
    &lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;</pre>


<p>Setting the height of the stub to the desired height of the container allows the content to align with the middle of the stub, vertically centered in the container.  Setting the <code>vertical-align</code> CSS property for both units tells them how to behave with repsect to the other units.</p>

<pre class="code prettyprint">&lt;style&gt;
#demo .align-stub {
    height: 200px;
}

#demo .align-stub,
#demo .yui-u-1-3 {
    vertical-align: middle;
}
&lt;&#x2F;style&gt;</pre>


<h5>Note:</h5>
<p>Because CSS examples are susceptible to other CSS on the page, this example is only available in a new window at the above link.</p>
</div>
        </div>

        <div id="sidebar" class="yui3-u">
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                                    <li data-description="Each unit has a className that provides its percentage width.">
                                        <a href="cssgrids-units.html">Using Grid Units</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This is a template for creating fixed-width layouts.">
                                        <a href="cssgrids-fixed.html">Fixed Page Template</a>
                                    </li>
                                
                            
                                
                                    <li data-description="This is a template for creating fluid layouts.">
                                        <a href="cssgrids-fluid.html">Fluid Page Template</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Basic CSS properties are leveraged to horizontally and vertically align units.">
                                        <a href="cssgrids-align.html">Aligning Grid Units</a>
                                    </li>
                                
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                            
                        </ul>
                    </div>
                </div>
            

            
                <div class="sidebox">
                    <div class="hd">
                        <h2 class="no-toc">Examples That Use This Component</h2>
                    </div>

                    <div class="bd">
                        <ul class="examples">
                            
                                
                            
                                
                            
                                
                            
                                
                            
                                
                                    <li data-description="Creating left navigation using the MenuNav Node Plugin.">
                                        <a href="../node-menunav/menunav-leftnav.html">Basic Left Nav</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Creating top navigation using the MenuNav Node Plugin">
                                        <a href="../node-menunav/node-menunav-2.html">Basic Top Nav</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Creating menu button navigation using the MenuNav Node Plugin">
                                        <a href="../node-menunav/node-menunav-3.html">Menu Button Top Nav</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Creating split button navigation using the MenuNav Node Plugin">
                                        <a href="../node-menunav/node-menunav-4.html">Split Button Top Nav</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Adding shadows to submenus of a left nav using the MenuNav Node Plugin">
                                        <a href="../node-menunav/node-menunav-5.html">Left Nav with Submenus with Shadows</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Adding rounded corners to submenus of a left nav using the MenuNav Node Plugin">
                                        <a href="../node-menunav/node-menunav-6.html">Left Nav With Submenus With Rounded Corners</a>
                                    </li>
                                
                            
                                
                                    <li data-description="Skining a menu built using the MenuNav Node Plugin to look like the menus on Flickr">
                                        <a href="../node-menunav/node-menunav-7.html">Skinning Menus Created Using the MenuNav Node Plugin</a>
                                    </li>
                                
                            
                        </ul>
                    </div>
                </div>
            
        </div>
    </div>
</div>

<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>

</body>
</html>
